var caches = [[1], [1, 1]]
function pascalMatrix(n) {
    while (caches[caches.length - 1].length * 2 - 1 < n) {
        var last = caches[caches.length - 1];
        var next = [1];
        for (var i = 0; i < last.length - 1; i++) {
            var x = last[i] + last[i + 1];
            next.push(x)
        }
        next.push(1);
        caches.push(next);
    }
    var res = [];
    for (row of caches) {
        var temp = []
        for (var i = 0; i < row.length - 1; i++) {
            temp.push(row[i]);
            temp.push(0);
        }
        temp.push(row[row.length - 1]);
        var d = Math.floor((n - temp.length) / 2);
        shit = Array(d).fill(0).concat(temp).concat(Array(d).fill(0));

        res.push(shit);
        if (row.length * 2 - 1 === n) break;
    }
    return res;
}
